export const getSetting = () => {
  return new Promise((resolve, reject) => {
    uni.getSetting({
      success(res) {
        resolve(res)
      },
      fail(err) {
        reject(err)
      }
    })
  })
}

export const chooseAddress = () => {
  return new Promise((resolve, reject) => {
    uni.chooseAddress({
      success(result) {
        resolve(result);
      },
      fail(err) {
        reject(err);
      }
    });
  })
}

export const openSetting = () => {
  return new Promise((resolve, reject) => {
    uni.openSetting({
      success(result) {
        resolve(result);
      },
      fail(err) {
        reject(err);
      }
    });
  })
}


export const showToast = ({ title }) => {
  return new Promise((resolve, reject) => {
    uni.showToast({
      title: title,
      icon: 'none',
      duration: 2000,
      success: (res) => {
        resolve(res)
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
}



export const login = () => {
  return new Promise((resolve, reject) => {
    uni.login({
      provider: "weixin",
      success: (loginRes) => {
        resolve(loginRes)
      },
      fail: (err) => {
        reject(err)
      }
    });
  })
}

export const dateFormat = (fmt, date) => {
  let ret;
  var date = new Date(date);
  const opt = {
    "Y+": date.getFullYear().toString(), // 年
    "m+": (date.getMonth() + 1).toString(), // 月
    "d+": date.getDate().toString(), // 日
    "H+": date.getHours().toString(), // 时
    "M+": date.getMinutes().toString(), // 分
    "S+": date.getSeconds().toString(), // 秒
    // 有其他格式化字符需求可以继续添加，必须转化成字符串
  };
  for (let k in opt) {
    ret = new RegExp("(" + k + ")").exec(fmt);
    if (ret) {
      fmt = fmt.replace(
        ret[1],
        ret[1].length == 1
          ? opt[k]
          : opt[k].padStart(ret[1].length, "0")
      );
    }
  }
  return fmt;

}





